
#ifndef RTMP_INCLUDE_CLIENT_H_
#define RTMP_INCLUDE_CLIENT_H_

#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <vector>
#ifndef RTMP_INCLUDE_MESSAGE_H_
#include "rtmp_message.h"
#endif
#ifndef RTMP_INCLUDE_PROCESS_H_
#include "rtmp_process.h"
#endif

struct RtmpClientUrl
{
    std::string m_protocol;
    std::string m_domain;
    uint16_t    m_port;
    std::string m_app;
    std::string m_stream;
};

class RtmpClient : public std::enable_shared_from_this<RtmpClient>
{
public:
    RtmpClient(Loop * loop);
    ~RtmpClient();
    bool ConnectionServer(const std::string & url);
    void SendMessage(std::shared_ptr<RtmpMessage> msg);

    bool ParseRtmpUrl(const std::string & url);
    void StartPullStream();
    void ChangeTask();
    void OnMessage(std::shared_ptr<SocketBuffer> socket);
    void OnError(std::string msg);
private:
    void SendC0C1();
    void SendConnect();
    void SendCreateStream();
    void SendGetStreamLength();
    void SendPlay();
    void SendMsg(std::shared_ptr<RtmpMessage> & msg);
    void UpdateStatus(int status);
private:
    Loop * m_loop;
    std::shared_ptr<Client> m_client;
    std::shared_ptr<RtmpConnection> m_conn;
private:
    RtmpClientUrl     m_url_info;
    std::map<int, std::vector<std::function<void()>>> m_status_func;
};

#endif
